<?php

/**
 * Talis Aspire Lists block
 *
 * @package     block
 * @subpackage  aspirelists
 * @copyright   2011 Lancaster University Network Services Limited
 * @license     http://www.gnu.org/licenses/lgpl.html GNU LGPL
 * @author      Andrew Nicols <andrew.nicols@luns.net.uk>
 */

defined('MOODLE_INTERNAL') || die;

function xmldb_block_aspirelists_upgrade($oldversion) {
    global $CFG, $DB;

    $dbman = $DB->get_manager();

    if ($oldversion < 2011101100) {
        $transaction = $DB->start_delegated_transaction();

        // Move configuration from targetAspire in the core config, to
        // targetaspire in the plugin config table
        if ($targetaspire = get_config('moodle', 'block_aspirelists_targetAspire')) {
            set_config('targetaspire', $targetaspire, 'blocks/aspirelists');
            unset_config('block_aspirelists_targetAspire');
        }

        // Move configuration from targetKG in the core config, to
        // knowledgegroup in the plugin config table
        if ($targetkg = get_config('moodle', 'block_aspirelists_targetKG')) {
            set_config('knowledgegroup', $targetkg, 'blocks/aspirelists');
            unset_config('block_aspirelists_targetKG');
        }

        $transaction->allow_commit();

        // Upgrade was successful
        upgrade_block_savepoint(true, 2011101100, 'aspirelists');
    }

    return true;
}
